ScenarioManagementController
The ScenarioManagementController provides comprehensive scenario and input management with full CRUD operations, enhanced data models, and integrated run management.
Overview
This controller consolidates both scenario and input management into a single controller, providing full CRUD operations for scenarios, input data, and simulation runs. It uses normalized DTOs and provides enhanced functionality compared to the basic ScenarioController.
Data Sources
- Azure Table Storage:
Inputstable for scenario and input dataRunstable for run metadata and status
- Configuration: Dependency injection for table service client
- No Blob Storage: Focuses on metadata management
Endpoints
Scenario Management
GET /api/scenariomanagement
Retrieves all scenarios.
Response:
- 200 OK: Returns list of
ScenarioDtoobjects - 500 Internal Server Error: Database error
Data Flow:
GET /api/scenariomanagement/{id}
Retrieves a specific scenario by ID.
Path Parameters:
id(string): Scenario identifier
Response:
- 200 OK: Returns
ScenarioDtoobject - 404 Not Found: Scenario not found
- 500 Internal Server Error: Database error
POST /api/scenariomanagement
Creates a new scenario.
Request Body:
{
"name": "string",
"description": "string",
"inputFile": "string",
"parameters": {}
}
Response:
- 201 Created: Returns created
ScenarioDtoobject - 400 Bad Request: Validation error
- 500 Internal Server Error: Database error
Data Flow:
PUT /api/scenariomanagement/{id}
Updates an existing scenario.
Path Parameters:
id(string): Scenario identifier
Request Body:
{
"name": "string",
"description": "string",
"inputFile": "string",
"parameters": {}
}
Response:
- 200 OK: Returns updated
ScenarioDtoobject - 404 Not Found: Scenario not found
- 400 Bad Request: Validation error
- 500 Internal Server Error: Database error
DELETE /api/scenariomanagement/{id}
Deletes a scenario.
Path Parameters:
id(string): Scenario identifier
Response:
- 204 No Content: Scenario deleted successfully
- 404 Not Found: Scenario not found
- 500 Internal Server Error: Database error
Input Management
GET /api/scenariomanagement/{scenarioId}/inputs
Retrieves all inputs for a specific scenario.
Path Parameters:
scenarioId(string): Scenario identifier
Response:
- 200 OK: Returns list of
ScenarioDtoobjects - 500 Internal Server Error: Database error
GET /api/scenariomanagement/{scenarioId}/inputs/{inputId}
Retrieves a specific input for a scenario.
Path Parameters:
scenarioId(string): Scenario identifierinputId(string): Input identifier
Response:
- 200 OK: Returns
ScenarioDtoobject - 404 Not Found: Input not found
- 500 Internal Server Error: Database error
POST /api/scenariomanagement/{scenarioId}/inputs
Creates a new input for a scenario.
Path Parameters:
scenarioId(string): Scenario identifier
Request Body:
{
"name": "string",
"type": "string",
"data": {},
"parameters": {}
}
Response:
- 201 Created: Returns created
ScenarioDtoobject - 400 Bad Request: Validation error
- 500 Internal Server Error: Database error
PUT /api/scenariomanagement/{scenarioId}/inputs/{inputId}
Updates an existing input for a scenario.
Path Parameters:
scenarioId(string): Scenario identifierinputId(string): Input identifier
Request Body:
{
"name": "string",
"type": "string",
"data": {},
"parameters": {}
}
Response:
- 200 OK: Returns updated
ScenarioDtoobject - 404 Not Found: Input not found
- 400 Bad Request: Validation error
- 500 Internal Server Error: Database error
DELETE /api/scenariomanagement/{scenarioId}/inputs/{inputId}
Deletes an input from a scenario.
Path Parameters:
scenarioId(string): Scenario identifierinputId(string): Input identifier
Response:
- 204 No Content: Input deleted successfully
- 404 Not Found: Input not found
- 500 Internal Server Error: Database error
Advanced Operations
GET /api/scenariomanagement/search
Searches scenarios by name or description.
Query Parameters:
searchTerm(string): Search term
Response:
- 200 OK: Returns filtered list of
ScenarioDtoobjects - 500 Internal Server Error: Database error
GET /api/scenariomanagement/statistics
Retrieves scenario statistics.
Response:
- 200 OK: Returns statistics object
- 500 Internal Server Error: Database error
Statistics Response:
{
"totalScenarios": 25,
"activeScenarios": 20,
"totalInputs": 150,
"averageInputsPerScenario": 6,
"scenariosWithRuns": 15,
"totalRuns": 300
}
GET /api/scenariomanagement/{id}/runs
Retrieves all runs for a specific scenario.
Path Parameters:
id(string): Scenario identifier
Response:
- 200 OK: Returns list of
RunDtoobjects - 500 Internal Server Error: Database error
POST /api/scenariomanagement/{id}/run
Creates and starts a new run for a scenario.
Path Parameters:
id(string): Scenario identifier
Request Body:
{
"startTime": "2023-11-16T00:00:00-05:00",
"endTime": "2023-11-16T23:59:59-05:00",
"reportingTimeStep": 15
}
Response:
- 201 Created: Returns created
RunDtoobject - 400 Bad Request: Validation error
- 500 Internal Server Error: Database error
GET /api/scenariomanagement/{scenarioId}/runs/{runId}
Retrieves a specific run for a scenario.
Path Parameters:
scenarioId(string): Scenario identifierrunId(string): Run identifier
Response:
- 200 OK: Returns
RunDtoobject - 404 Not Found: Run not found
- 500 Internal Server Error: Database error
Data Models
ScenarioDto
public class ScenarioDto
{
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string InputFile { get; set; }
public Dictionary<string, object> Parameters { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public bool IsActive { get; set; }
}
CreateScenarioRequest
public class CreateScenarioRequest
{
[Required]
public string Name { get; set; }
public string Description { get; set; }
[Required]
public string InputFile { get; set; }
public Dictionary<string, object> Parameters { get; set; }
}
UpdateScenarioRequest
public class UpdateScenarioRequest
{
[Required]
public string Name { get; set; }
public string Description { get; set; }
[Required]
public string InputFile { get; set; }
public Dictionary<string, object> Parameters { get; set; }
}
CreateInputRequest
public class CreateInputRequest
{
[Required]
public string Name { get; set; }
[Required]
public string Type { get; set; }
public Dictionary<string, object> Data { get; set; }
public Dictionary<string, object> Parameters { get; set; }
}
Azure Storage Details
Table Storage Schema
Inputs Table:
- PartitionKey:
{scenarioId} - RowKey:
{inputId} - Properties: Name, Type, Data, Parameters, CreatedAt, UpdatedAt, IsActive
Runs Table:
- PartitionKey:
{scenarioId} - RowKey:
{runId} - Properties: Status, StartTime, EndTime, ReportingTimeStep, InputFile, Flow, Flooding, CreatedAt, CompletedAt
Error Handling
- Validation Errors: Returns 400 with validation details
- Not Found: Returns 404 for missing entities
- Database Errors: Returns 500 with error logging
- Concurrent Access: Handles ETag conflicts
- Business Logic: Validates scenario-input relationships
Performance Considerations
- Async Operations: All database operations are async
- Pagination: Supports large result sets
- Indexing: Optimized for scenario and input queries
- Caching: No built-in caching (consider for frequently accessed data)
- Batch Operations: Efficient bulk operations
Dependencies
Azure.Data.TablesSwmmModels.DTOsSwmmModels.RequestsSwmmModels.ValidatorsSystem.ComponentModel.DataAnnotations
Workflow Integration
Scenario Lifecycle
Input Management
Monitoring and Logging
- Request Logging: All operations are logged
- Error Tracking: Detailed error information
- Performance Metrics: Scenario and input statistics
- Audit Trail: Complete history of changes
Security Considerations
- Input Validation: All inputs are validated
- Authorization: Requires proper authentication
- Data Sanitization: Prevents injection attacks
- Access Control: Scenario-based access control
- Data Integrity: Maintains referential integrity
Usage Examples
Create New Scenario:
POST /api/scenariomanagement
{
"name": "Urban Stormwater",
"description": "Urban area stormwater simulation",
"inputFile": "urban.inp",
"parameters": {
"rainfallIntensity": 2.5,
"imperviousness": 0.8
}
}
Add Input to Scenario:
POST /api/scenariomanagement/scenario1/inputs
{
"name": "Rainfall Data",
"type": "rainfall",
"data": {
"timeSeries": [...],
"units": "mm/hr"
}
}
Start Simulation Run:
POST /api/scenariomanagement/scenario1/run
{
"startTime": "2023-11-16T00:00:00-05:00",
"endTime": "2023-11-16T23:59:59-05:00",
"reportingTimeStep": 15
}